package ListNode;

import ListNode.MySingleList.ListNode;

public class MySingleList {
      static class ListNode{
    	  int val;
    	  ListNode next = null;
    	  ListNode(int val){
    		  this.val = val;
    	  }
    	  
      }
      public ListNode head;
      public void addFirst(int data) {
    		ListNode node = new ListNode(data);
    		node.next = this.head;
    		this.head = node;
    	}
      public void display() {
    	  ListNode cur = head;
    	  while(cur!=null){
    	  System.out.print(cur.val+" ");
    	  cur = cur.next;
    	  }
    	  System.out.println();
      }
      
public void removeAllKey(int key) {
	if(this.head == null) {
		return;
	}
	
	ListNode cur = this.head.next;
	ListNode prev = this.head;
	while(cur!= null) {
		if(cur.val == key) {
			prev.next=cur.next;
			cur = cur.next;
			
		}else {
			prev=cur;
			cur = cur.next;
		}
	}

}
}
